<template>
  <a-layout id="components-layout-demo-custom-trigger">
    <a-layout-sider v-model="collapsed" :trigger="null" collapsible>
      <div class="logo" />
      <a-menu
        :default-selected-keys="[this.$route.path.split('/')[2]]"
        :default-open-keys="[this.$route.path.split('/')[1]]"
        mode="inline"
        theme="dark"
        :inline-collapsed="collapsed"
      >
        <a-sub-menu :key="item.key" v-for="item in menuList">
          <span slot="title">
            <a-icon :type="item.icon" />
            <span>{{item.menuName}}</span>
          </span>
          <a-menu-item :key="array.id" v-for="array in item.children">
            <router-link :to="array.menuUrl">{{array.menuName}}</router-link>
          </a-menu-item>
        </a-sub-menu>
      </a-menu>
      <!-- <app-side></app-side> -->
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <div class="left-content-header">
          <a-icon
            class="trigger"
            :type="collapsed ? 'menu-unfold' : 'menu-fold'"
            @click="() => (collapsed = !collapsed)"
          />
          <app-mianbao></app-mianbao>
        </div>
        <div class="right-content-header">
          <div>app二维码</div>
          <div>
            <img src="../assets/logo.png" alt class="userimg" />
            <span>{{accountInfo.userName}}</span>
            <a-dropdown>
              <a-icon type="caret-down" style="margin-left:5px" @click="e => e.preventDefault()" />
              <a-menu slot="overlay" @click="handleMenuClick">
                <a-menu-item key="1">个人信息</a-menu-item>
                <a-menu-item key="2">修改密码</a-menu-item>
                <a-menu-item key="3">退出账号</a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
        </div>
      </a-layout-header>
      <a-layout-content :style="{ margin: '24px 16px', padding: '24px', background: '#fff', }">
        <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script>
import appSide from "./layout/side";
import appMianbao from "./miaobao";
import { mapState } from "vuex";
export default {
  name: "HelloWorld",
  components: {
    appSide,
    appMianbao
  },
  data() {
    return {
      collapsed: false,
      menuList: []
    };
  },
  computed: {
    ...mapState({
      accountInfo: state => state.account
    })
  },
  mounted() {
    this.initData();
  },
  methods: {
    //请求菜单
    initData() {
      // this.$axios.post("/menu/service/findMenuByUserId").then(res => {
    ///menu/service/findByPage
      this.$axios.post("/menu/service/findByPage").then(res => {
        console.log("888cbncnn", res.data);
        this.menuList = res.data
      });
      this.$forceUpdate();
    },
    handleMenuClick(e) {
      console.log("click", e);
      if (e.key == 3) {
        localStorage.removeItem("userInfo");
        localStorage.removeItem("token");
        this.$router.push({
          path: "/login"
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.ant-layout.ant-layout-has-sider {
  height: 100%;
}
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
}
.header-box {
  padding: 0 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .right-content-header {
    display: flex;
  }
}
.userimg {
  width: 50px;
  height: 50px;
}
.ant-layout-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.right-content-header {
  display: flex;
  margin-right: 20px;
}
.left-content-header {
  display: flex;
  align-items: center;
}
  .ant-menu-inline{
    border: none;
  }
</style>